import Vue from 'vue'
import Vuex from 'vuex'
import {
  getInfo
} from "@/api/login";
import {
  setUser
} from '@/util/auth'
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    userInfo: null,
    tooken: '',
    courseData: {},
    videoList: [],
    testList: [],
    examData: {},
    questionType: {
      1: '单选题',
      2: '多选题',
      3: '判断题',
      4: '填空题',
      5: '简答题',
    },
    isSign: false,
    hisRoute: []
  },
  getters: {
    getUserInfo: state => {
      return state.userInfo
    },
    getCourseData: state => {
      return state.courseData
    },
    getVideoList: state => {
      return state.videoList
    },
    getTestList: state => {
      return state.testList
    },
    getExamData: state => {
      return state.examData
    },
    getQuestionType: state => {
      return state.questionType
    },
    getIsSign: state => {
      return state.isSign
    },
    getHisRoute: state => {
      return state.hisRoute
    }
  },
  mutations: {
    setUserInfo(state, data) {
      state.userInfo = data
    },
    SetCourseData(state, data) {
      state.courseData = data
    },
    SetVideoList(state, data) {
      state.videoList = data
    },
    SetTestList(state, data) {
      state.testList = data
    },
    SetExamData(state, data) {
      state.examData = data
    },
    SetIsSign(state, data) {
      state.isSign = data
    },
    SetHisRoute(state, data) {
      state.hisRoute = data
    }
  },
  actions: {
    getUserInfo({
      commit,
      state
    }) {
      return getInfo().then(res => {
        commit('setUserInfo', res.user)
      })
    }
  }
})
export default store
